package com.storydo.file.share.runner;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
import org.springframework.context.annotation.Configuration;

import com.storydo.file.share.config.FileConfiguration;
import com.storydo.file.share.rest.AuthController;
import com.storydo.file.share.utils.NetUtil;
import com.storydo.file.share.utils.UUIDUtils;



@Configuration
public class RunnerStart implements CommandLineRunner{

	@Autowired
	private ServletWebServerApplicationContext appContext;
	
	@Autowired
	FileConfiguration fileConfig;
	
	@Override
	public void run(String... args) throws Exception {
		String localIp = NetUtil.localIPv4();
		System.out.println("-----------------------------------------------");
		System.out.println("-----------------------------------------------");
		System.out.println("--可选参数---------------------------------------");
		System.out.println("--server.port=8080			指定服务启动端口");
		System.out.println("--file.path=.				共享的目录,默认程序运行路径");
		System.out.println("--file.file-size=200			目录下最大的文件数");
		System.out.println("--file.upload=false			允许上传文件 true/false");
		System.out.println("--file.auth=false			是否需要验证 true/false");
		System.out.println("");
		System.out.println("当前共享目录: " + fileConfig.getWorkPath().toString());
		System.out.println("如果开启上传功能,文件默认会上传到 ${file.path}/upload 下");
		System.out.println("请通过 -> " + 
				String.format("http://%s:%d/ 访问共享服务", localIp, appContext.getWebServer().getPort()));
		if (fileConfig.isAuth()) {
			AuthController.CHECK_CODE = UUIDUtils.generateShortUuid();
			System.out.println("当前权限校验已开启, 校验码为: " + AuthController.CHECK_CODE);
		}
	}

}
